package com.example.myapplication6;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.fragment.app.Fragment;

public class Step3Fragment extends Fragment {
    private Order order;
    private EditText etName, etPhone;

    public void setOrder(Order order) {
        this.order = order;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_step, container, false);
        TextView tvTitle = view.findViewById(R.id.tv_title);
        LinearLayout llContent = view.findViewById(R.id.ll_content);
        Button btnNext = view.findViewById(R.id.btn_next);

        tvTitle.setText("步骤3：填写乘客信息");

        // 添加姓名输入框
        etName = new EditText(getContext());
        etName.setHint("请输入姓名");
        llContent.addView(etName);

        // 添加手机号输入框（设置间距）
        etPhone = new EditText(getContext());
        etPhone.setHint("请输入手机号");
        etPhone.setInputType(android.text.InputType.TYPE_CLASS_PHONE);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT
        );
        params.topMargin = 10;
        etPhone.setLayoutParams(params);
        llContent.addView(etPhone);

        // 下一步（保存信息）
        btnNext.setOnClickListener(v -> {
            order.name = etName.getText().toString();
            order.phone = etPhone.getText().toString();
            ((MainActivity) getActivity()).goToStep(3);
        });

        return view;
    }
}